import tpl from './emptyTime.tpl'
import './emptyTime.scss'

import { tplReplace } from '../../../utils/tools';

export default _ => {
    return {
        name: 'emptyTime',
        tpl( obj, daySign ) {
            let list = '',
                el = typeof obj == 'number' ? obj : obj.length;

            for( let i = 0; i < el; i++ ) {
                
                list += tplReplace( tpl, {
                    disped: this.ChangeTime( daySign, i ),
                    sign: typeof obj == 'number' ? '' : 'sign',
                    index: typeof obj == 'number' ? '' : obj[i]
                })
            }
            return list;
        },

        ChangeTime( { year, month, day }, idx ) {
            let now = new Date(),
                newyear = now.getFullYear(),
                NewMonth = now.getMonth() + 1,
                type = '';

            // 年月相等的情况下 只需要筛选出当前月还未到达的日期  反之 当前的月分如果比传进来的月份小 那一定是禁用的
            if ( newyear == year && NewMonth == month ) {
                if ( idx + 1 > parseInt( day ) ) {
                    type = 'disped';
                }
            } else if ( NewMonth < month ) {
                type = 'disped';
            } else if ( newyear < year ) {
                type = 'disped';
            }
            
            return type;
        }   

    }
}